package com.example.authority.component;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.authority.entity.Files;
import com.example.authority.entity.Friendapply;
import com.example.authority.service.FileService;
import com.example.authority.service.FriendapplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 定时任务类，定时处理删除文件以及好友申请删除
 */
@Component
@Slf4j
public class AutoTask {
    @Autowired
    private FriendapplyService friendapplyService;

    @Autowired
    private FileService fileService;

    @Scheduled(cron = "0 00 4 * * ?")
    public void DeleteOutTimeFriendApply() {
        log.info("定时处理拒绝好友请求");
        QueryWrapper<Friendapply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", 2);
        friendapplyService.remove(queryWrapper);
    }

    @Scheduled(cron = "0 0 0 1 * ?")
    public void DeleteOutTimeFlie() {
        log.info("定时处理已删除文件");
        QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", 1);
        fileService.remove(queryWrapper);
    }
}
